//
//  DefaultTableViewCell.swift
//  EasePods
//
//  Created by 李然 on 2024/5/21.
//

import UIKit

class DefaultTableViewCell: TableViewCell {

    override func makeUI() {
        super.makeUI()
        
        backgroundColor = R.color.common_2_bg_page()
        
        stackView.addArrangedSubview(titleL)
        let spaceLabel = Label()
        spaceLabel.text = " "
        spaceLabel.setPriority(.fittingSizeLevel, for: .horizontal)
        stackView.addArrangedSubview(spaceLabel)
        stackView.addArrangedSubview(detailL)
        stackView.addArrangedSubview(arrowView)
        
        stackView.addSubview(badgeView)
        badgeView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 6, height: 6))
            make.centerY.equalTo(titleL.snp.top)
            make.leading.equalTo(titleL.snp.trailing).offset(6)
        }
    }
    
    func bind(viewModel: DefaultCellViewModel) {
        viewModel.detail.asDriver().drive(self.detailL.rx.text).disposed(by: cellDisposeBag)
        viewModel.arrow.asDriver().map{ !$0 }.drive(self.arrowView.rx.isHidden).disposed(by: cellDisposeBag)
        viewModel.badge.asDriver().map{ !$0 }.drive(self.badgeView.rx.isHidden).disposed(by: cellDisposeBag)
    }

    lazy var titleL: UILabel = {
        let label = UILabel()
        label.textColor = R.color.common_3_text()
        label.font = Fonts.systemFont(ofSize: 14)
        label.numberOfLines = 0
        return label
    }()
    
    lazy var detailL: UILabel = {
        let label = UILabel()
        label.textColor = R.color.common_11_text_list()
        label.font = Fonts.systemFont(ofSize: 14)
        label.numberOfLines = 0
        return label
    }()
    
    lazy var arrowView: UIImageView = {
        let view = UIImageView()
        view.image = R.image.ic_common_list_more()
        return view
    }()

    lazy var badgeView: UIImageView = {
        let view = UIImageView()
        view.layer.cornerRadius = 3
        view.isHidden = true
        view.backgroundColor = R.color.common_13_warn()
        return view
    }()
}
